package com.um.jdy.ykc.command;

import com.um.jdy.ykc.utils.RadixsUtil;
import lombok.Data;

/**
 * 参数配置（充电桩->运营平台）
 *
 * @author 甘天伟
 * @since 2022/6/28
 * 版权所有 广州优匠科技有限公司
 */
@Data
public class Cmd17BmsSettings extends YkcCommand {

    /**
     * 交易流水号：16个字节
     */
    private String transactionNo;

    /**
     * 桩编码：7个字节
     */
    private String code;

    /**
     * 枪号：1个字节
     */
    private int gunNo;

    /**
     * BMS 单体动力蓄电池最高允许充电电压：2个字节
     */
    private int bmsSingleBatteryAllowVoltage;

    /**
     * BMS 最高允许充电电流：2个字节
     */
    private int bmsAllowMaxElectricity;

    /**
     * BMS 动力蓄电池标称总能量：2个字节
     */
    private int bmsBatteryTotalPower;

    /**
     * BMS 最高允许充电总电压：2个字节
     */
    private int bmsAllowMaxVoltage;

    /**
     * BMS 最高允许温度：1个字节
     */
    private int bmsAllowMaxTemperature;

    /**
     * BMS 整车动力蓄电池荷电状态(soc)：1个字节
     */
    private int bmsSoc;

    /**
     * BMS 整车动力蓄电池当前电池电压：2个字节
     */
    private int bmsBatteryCurrentVoltage;

    /**
     * 电桩最高输出电压：2个字节
     */
    private int maxOutputVoltage;

    /**
     * 电桩最低输出电压：2个字节
     */
    private int minOutputVoltage;

    /**
     * 电桩最高输出电流：2个字节
     */
    private int maxOutputElectricity;

    /**
     * 电桩最低输出电流：2个字节
     */
    private int minOutputElectricity;

    @Override
    public void parseBytes(byte[] bytes) {
        super.parseBytes(bytes);
        transactionNo = RadixsUtil.bytesToHexString(readBytes(data, 0, 16));
        code = RadixsUtil.bytesToHexString(readBytes(data, 16, 7));
        gunNo = RadixsUtil.byteToInteger(data[23]);
        bmsSingleBatteryAllowVoltage = RadixsUtil.bytesToInteger(readBytes(data, 24, 2));
        bmsAllowMaxElectricity = RadixsUtil.bytesToInteger(readBytes(data, 26, 2));
        bmsBatteryTotalPower = RadixsUtil.bytesToInteger(readBytes(data, 28, 2));
        bmsAllowMaxVoltage = RadixsUtil.bytesToInteger(readBytes(data, 30, 2));
        bmsAllowMaxTemperature = RadixsUtil.byteToInteger(data[32]);
        bmsSoc = RadixsUtil.bytesToInteger(readBytes(data, 33, 2));
        bmsBatteryCurrentVoltage = RadixsUtil.bytesToInteger(readBytes(data, 35, 2));
        maxOutputVoltage = RadixsUtil.bytesToInteger(readBytes(data, 37, 2));
        minOutputVoltage = RadixsUtil.bytesToInteger(readBytes(data, 39, 2));
        maxOutputElectricity = RadixsUtil.bytesToInteger(readBytes(data, 41, 2));
        minOutputElectricity = RadixsUtil.bytesToInteger(readBytes(data, 43, 2));

        transactionNo = RadixsUtil.getTransactionNo(transactionNo);
        code = RadixsUtil.getCode(code);
    }
}
